﻿using System;
using Assist;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKView;

namespace YJKAxisAndEdit
{
	[Regeneration(RegenerationOption.Manual)]
	[Transaction(TransactionMode.Manual)]
	public class CmdAddAxis : YJKCommandManual
	{
		protected override Result YJKExcute(ExternalCommandData cmdData, ref string message, ElementSet elements)
		{
			CmdViewType types = (CmdViewType)11;
			if (SwitchView.SetUsableView(types, cmdData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			Transaction transaction = new Transaction(this.m_doc, this.ToString());
			transaction.Start();
			Result result = this.AddAxis(cmdData, ref message);
            if (result == Autodesk.Revit.UI.Result.Succeeded)
			{
				transaction.Commit();
			}
			else
			{
				transaction.RollBack();
			}
			return result;
		}

		private Result AddAxis(ExternalCommandData cmdData, ref string message)
		{
			AixsCreator aixsCreator = new AixsCreator(cmdData);
			Result result;
			do
			{
				result = aixsCreator.Create(ref message);
			}
			while (result == Autodesk.Revit.UI.Result.Succeeded);
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
